package com.galeno;

import org.apache.flink.configuration.Configuration;
import org.apache.flink.streaming.api.datastream.AllWindowedStream;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.windowing.windows.GlobalWindow;

/**
 * @author galeno
 * @Title:
 * @Description:
 * @date 2021/10/2010:42
 */
public class CountWindowDemo {
    public static void main(String[] args) throws Exception {
        Configuration conf = new Configuration();
        conf.setInteger("rest.port",8081);
        StreamExecutionEnvironment locEnvWebUI = FlinkUtils.getLocEnvWebUI(conf);
        DataStreamSource<String> lines = locEnvWebUI.socketTextStream(FlinkUtils.LinuxURL, FlinkUtils.port);

        SingleOutputStreamOperator<Integer> map = lines.map(Integer::parseInt);

        AllWindowedStream<Integer, GlobalWindow> windowd = map.countWindowAll(3);
       //sum做增量聚合
        SingleOutputStreamOperator<Integer> sum = windowd.sum(0);

        sum.print();
        locEnvWebUI.execute();
    }
}
